{block name=body}
 <div class="row form">
	<form class="form-inline" role="form" id="filter-orders-form">
		<div class="form-group">
			<label class="" for="from">从:</label> 
			<input type="text" class="form-control dates" value="{'-1 month'|date_format:"%Y-%m-%d"}" name="from" id="from" required>
		</div>
		<div class="form-group">
			<label class="" for="to">To:</label> 
			<input type="text" class="form-control dates" value="{$smarty.now|date_format:"%Y-%m-%d"}" name="to" id="to" required>
		</div>
		<a href="javascript:void(0);" onClick="$('#filter-orders-form').submit();" class="btn btn-info" style="margin-left: 10px;">筛选</a>
		<a href="javascript:void(0);" onClick="getlabel();" class="btn btn-info" style="margin-left: 10px;">获取标签</a>
	</form>
	<form id="label-form" action="/admin/includes/processes/processes-label.php" method="post" target="_blank">
		<input type="hidden" value="" name="from" id="label-from">
		<input type="hidden" value="" name="to" id="label-to">
	</form>
</div> 
<div class="row form">
	<table class="table table-bordered table-striped table-hover" id="orders-table">
		<thead>
			<tr>
				<th colspan="3">{$zone|upper}</th>
				<th>
					<select class="form-control" name="status" id="status">
						<option value="0">所有状态</option>
						{foreach $options.status as $opt}
								<option value="{$opt.id}"}>{$opt.value}</option>
						{/foreach} 
					</select>
				</th>
				<th></th>
			</tr>
		</thead>
		<tbody>
			{include file='orders.tpl'}
		</tbody>
	</table>
</div>

<script>
function getOrdersFiltered () {
	$('body').css('cursor','wait');
	var datastring = $("#filter-orders-form").serialize();
	$.ajax({
		type: "POST",
	    url: "/admin/includes/processes/load-orders.php",
		cache: false,
		data: datastring,
		dataType: "html",
	    success: function(data) {
	    	try{
	    		var obj = $.parseJSON(data);
	    		$('#status').val('0');
			 	$('#orders-table tbody').html(obj.body);
					$('body').css('cursor','default');
			    
			}catch(err){
				$('body').css('cursor','default'); 
				console.log('TRY-CATCH error');
			}
	    },
		error: function(){
			$('body').css('cursor','default'); 
			console.log('AJAX error');
         	}
	});
}

	$(document).ready(function() {

		$("#to").datepicker({
			changeMonth : true,
			changeYear : true,
			dateFormat : "dd/mm/yy",
			maxDate : new Date(),
			onSelect : function(selectedDate) {
				$("#from").datepicker("option", "maxDate", selectedDate);
			}
		});

		$("#from").datepicker({
			changeMonth : true,
			changeYear : true,
			dateFormat : "dd/mm/yy",
			maxDate : new Date(),
			onSelect : function(selectedDate) {
				$("#to").datepicker("option", "minDate", selectedDate);
			}
		});

		$('#filter-orders-form').validate();

		$('#status').change(function(){
			if ( $(this).val() == 0 ) {
				$('.order').show();
			} else {
				$('.order').hide();
				$('.'+ $(this).val() ).show();
			}
			checkVisible();
		});
		
	});

	function getlabel(){
		$('#label-from').val( $('#from').val() );
		$('#label-to').val( $('#to').val() );
		$('#label-form').submit();
	}

	


	function checkVisible() {
		if ( $('.order:visible').length > 0 ) {
			$('.no-orders').hide();
		} else {
			$('.no-orders').show();
		}
	}
</script>
{/block}
